﻿using Infrastructure.app;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Security.Claims;

namespace Infrastructure
{
    public static class App
    {
        public static IServiceProvider ServiceProvider => HttpContext?.RequestServices ?? InternalApp.ServiceProvider;

        public static HttpContext HttpContext => HttpContextLocal.Current();

        public static ClaimsPrincipal User => HttpContext?.User;

        public static TService GetService<TService>() where TService : class
        {
            return GetService(typeof(TService)) as TService;
        }

        public static object GetService(Type type)
        {
            return ServiceProvider.GetService(type);
        }

        public static TService GetRequiredService<TService>() where TService : class
        {
            return GetRequiredService(typeof(TService)) as TService;
        }

        public static object GetRequiredService(Type type)
        {
            return ServiceProvider.GetRequiredService(type);
        }
    }
}
